<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js文档对象模型</title>
    <style type="text/css">
        .bg {
            background-color: black;
        }

        .ft {
            background-color: green;
        }
    </style>
    <script type="text/javascript">
        function changeStyle()
        {
            // document.div.style.backgroundColor="red";
            var bg = document.getElementById("myDiv");
            bg.style.backgroundColor = "red";
        }  
        </script>
</head>

<body>
    <div id="myDiv" class="bg" title="div" onmouseover="changeStyle()" onmouseout="document.getElementById('myDiv').style.backgroundColor='black'">
        <img id="img1">
        <a href="https://www.sohu.com/a/339884382_500262" id="myA"></a>
    </div>
    <input type="button" onclick="changeStyle()" value="Change bg colors">

</body>

</html>